﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.InterceptionExtension;
using Microsoft.Practices.Unity;

namespace Negocio.Aspectos
{
    public class Monitoracao : IInterceptionBehavior
    {
        [Dependency]
        public IContador Contador
        {
            get;
            set;
        }

        public IEnumerable<Type> GetRequiredInterfaces()
        {
            return Type.EmptyTypes;
        }

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            var returnValue = getNext()(input, getNext);
            Contador.AdicionarContador();
            string nomeFila = System.Configuration.ConfigurationManager.AppSettings["queueDecisao"];
            MensageriaComum.Mensageria.Enviar(nomeFila, Contador.ObterContagem());
            return returnValue;
        }

        public bool WillExecute
        {
            get 
            { 
                return true; 
            }
        }
    }
}
